package online.inote.naruto.api.access.admin.modules.system.entity;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.FieldNameConstants;
import online.inote.naruto.api.access.admin.modules.base.entity.SignatureEntity;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.Date;

/**
 * @description API实体对象
 * @author XQF.Sui
 * @date 2021/08/05 18:28
 */
@Data
@EqualsAndHashCode(callSuper = true)
@FieldNameConstants
@Entity
@Table(
    name = "naruto_api",
    uniqueConstraints =
        @UniqueConstraint(columnNames = {ApiEntity.Fields.type, ApiEntity.Fields.method}))
public class ApiEntity extends SignatureEntity {

  private static final long serialVersionUID = 1113275316057287063L;

  @Id
  @Column(length = 36)
  protected String id;

  /** 名称 */
  @NotBlank(message = "名称不能为空")
  @Column(nullable = false, length = 64)
  private String name;

  /** 类 */
  @NotBlank(message = "类不能为空")
  @Column(nullable = false, length = 64)
  private String type;

  /** 方法 */
  @NotBlank(message = "方法不能为空")
  @Column(nullable = false, length = 32)
  private String method;

  /** 是否启用 */
  @NotNull(message = "是否启用不能为空")
  @Column(nullable = false)
  private Boolean enable;

  /** 创建时间 */
  @Column(nullable = false)
  @JSONField(format = "yyyy-MM-dd HH:mm:ss")
  @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
  private Date createTime;

  @Transient private Long authSystemNumber;
  @Transient private String systemId;
  @Transient private Boolean isAuth;

  public String getClassMethod() {
    return this.type + "." + this.method;
  }
}
